package chapter7.No7_2_线程组.g递归与非递归取得组内对象;

/**
 * !
 *
 * @author liujian
 * @version 2016/12/8 0008
 */
public class Main {
    public static void main(String[] args) {
        ThreadGroup mainGroup = Thread.currentThread().getThreadGroup();
        ThreadGroup aGroup = new ThreadGroup(mainGroup, "A");
        ThreadGroup a1Group = new ThreadGroup(aGroup, "A1");

        System.out.println("=========== 递归 ===========");
        ThreadGroup[] mainTG = new ThreadGroup[mainGroup.activeGroupCount()];
        mainGroup.enumerate(mainTG, true);

        for (ThreadGroup t : mainTG) {
            System.out.println(t.getName());
        }

        System.out.println("=========== 非递归 ===========");
        ThreadGroup[] mainTG2 = new ThreadGroup[mainGroup.activeGroupCount()];
        mainGroup.enumerate(mainTG2, false);

        for (ThreadGroup t : mainTG2) {
            if(t != null) {
                System.out.println(t.getName());
            }
        }

    }
}
